package misscl.online.slh_gym.util;

import java.util.HashMap;
import java.util.Map;

public class AjaxResult {


    //判断成功还是失败
    private boolean success;
    //自定义状态码
    private Integer code;
    //状态码描述
    private String message;
    //数据保存
    private Map<String,Object> data =new HashMap<String, Object>();

    //--------------------
    public boolean getSuccess(){return success;}

    public void setSuccess(Boolean success){this.success=success;}

    //--------------------

    public Integer getCode(){ return code; }

    public void setCode(Integer code){ this.code =code;}

    //--------------------

    public String getMessage(){ return  message;}

    public void setMessage(String message){this.message=message;}

    //--------------------
    public Map<String,Object> getData(){return data; }

    public void setData(Map<String,Object> data){this.data=data;}

    //把构造方法私有化
    private AjaxResult(){}

    //成功静态方法
    public static AjaxResult ok(String message){

        AjaxResult r = new AjaxResult();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage(message);
        return r;

    }

    //失败静态方法
    public static AjaxResult error(String message){

        AjaxResult r = new AjaxResult();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage(message);
        return r;
    }

    //验证码成功静态方法
//    public static AjaxResult captchaOk(){
//
//        AjaxResult r = new AjaxResult();
//        r.setSuccess(true);
//        r.setCode(ResultCode.CAPTCHASUCCESS);
//        r.setMessage("成功");
//        return r;
//
//    }

    //验证码失败静态方法
    public static AjaxResult captchaError(String message){

        AjaxResult r = new AjaxResult();
        r.setSuccess(false);
        r.setCode(ResultCode.CAPTCHAERROR);
        r.setMessage(message);
        return r;

    }




    public AjaxResult data(String key,Object value){

        this.data.put(key,value);
        return this;

    }

    public AjaxResult data(Map<String,Object> map){

        this.setData(map);

        return this;
    }

}
